#ifndef ACAPELLA_SYNCHRONIZE_SPIN_LOCK_LINUX_HPP
#define ACAPELLA_SYNCHRONIZE_SPIN_LOCK_LINUX_HPP

#include <pthread.h>

namespace acapella
{
namespace synchronize
{

class spin_lock
{
public:

	spin_lock()
	{
		pthread_mutex_init(&v_, NULL);
	}

	~spin_lock()
	{
		pthread_mutex_destroy(&v_);
	}

	bool try_lock()
	{
		return pthread_mutex_trylock( &v_ ) == 0;
	}

	void lock()
	{
		pthread_mutex_lock( &v_ );
	}

	void unlock()
	{
		pthread_mutex_unlock( &v_ );
	}

private:
	pthread_mutex_t v_;

	spin_lock(const spin_lock&);
	spin_lock& operator=(const spin_lock&);
};


}
}


#endif
